package com.multitrack.main;

import android.app.TabActivity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

import com.multitrack.datatype.STATE;
import com.multitrack.map.TrackMapActivity;

public class TabMenuActivity extends TabActivity {

	static final String TAG = "TabMenuActivity";

	TabHost mTab;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		Drawable event = getResources().getDrawable(R.drawable.event);
		Drawable tracking = getResources().getDrawable(R.drawable.tracking);
		Drawable setting = getResources().getDrawable(R.drawable.setting);

		Intent inIntent = getIntent();

		STATE resultState = (STATE) inIntent
				.getSerializableExtra(STATE.MESSAGE);

		Intent intent = null;

		switch (resultState) {
		case SOCKET_SUCCESS:
			intent = new Intent(this, EventActivity.class);
			break;

		case SOCKET_FAIL:
		case SOCKET_EXCEPTION:
			intent = new Intent(this, NoticeActivity.class);
			break;
		}

		mTab = getTabHost();

		mTab.addTab(mTab.newTabSpec("tag0").setIndicator("Event")
				.setContent(intent).setIndicator("Event", event));

		mTab.addTab(mTab.newTabSpec("tag1").setIndicator("Tracking")
				.setContent(new Intent(this, NoticeActivity.class))
				.setIndicator("Tracking", tracking));

		mTab.addTab(mTab.newTabSpec("tag2").setIndicator("Setting")
				.setContent(new Intent(this, SettingActivity.class))
				.setIndicator("Setting", setting));

		mTab.setOnTabChangedListener(new OnTabChangeListener() {
			public void onTabChanged(String tabId) {
				if (tabId.equals("tag1") == true) {
					Intent intent = new Intent(TabMenuActivity.this,
							TrackMapActivity.class);
					startActivity(intent);
					mTab.setCurrentTabByTag("tag0");
				}
			}
		});
		
		
	}
}